package cn.ac.siom.query.dao.impl;

import cn.ac.siom.query.dao.ITab_ThesisDao;
import cn.ac.siom.query.vo.Tab_Thesis;
import cn.ac.siom.query.vo.resultType_jl;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Repository
public class Tab_ThesisDaoImpl extends SqlSessionDaoSupport implements ITab_ThesisDao {
    @Autowired
    public Tab_ThesisDaoImpl(SqlSessionFactory sqlSessionFactory) {
        super.setSqlSessionFactory(sqlSessionFactory);
    }


    @Override
    public boolean doCreate(Tab_Thesis vo) throws SQLException {
        return false;
    }

    @Override
    public boolean doUpdate(Tab_Thesis vo) throws SQLException {
        return false;
    }

    @Override
    public boolean doRemove(Set<?> ids) throws SQLException {
        return false;
    }

    @Override
    public Tab_Thesis findById(Integer i_id) throws SQLException {
        return (Tab_Thesis) super.getSqlSession().selectList("Tab_ThesisNS.findNO");
    }

    @Override
    public List<Tab_Thesis> findAll() throws SQLException {
        return super.getSqlSession().selectList("Tab_ThesisNS.findAll");
    }


    @Override
    public List<Tab_Thesis> findAllBySplit(String column, String keyWord, Integer currentPage, Integer lineSize) throws SQLException {
        return null;
    }


    @Override
    public List<Tab_Thesis> findReport() throws SQLException {
        return super.getSqlSession().selectList("Tab_ThesisNS.findReport");
    }

    @Override
    public List<Tab_Thesis> findBookSection() throws SQLException {
        return super.getSqlSession().selectList("Tab_ThesisNS.findBookSection");
    }

    @Override
    public List<Tab_Thesis> findJournal() throws SQLException {
        return super.getSqlSession().selectList("Tab_ThesisNS.findJournal");
    }

    @Override
    public List<Tab_Thesis> findConference() throws SQLException {
        return super.getSqlSession().selectList("Tab_ThesisNS.findConference");
    }

    @Override
    public List<Tab_Thesis> findNo(Integer id) throws SQLException {
        Map<String, Integer> map = new HashMap<>();
        map.put("i_id", id);
        return super.getSqlSession().selectList("Tab_ThesisNS.findNo", map);
    }

    @Override
    public List<Tab_Thesis> findSearch(Integer rownum, Integer page_id, String keywords) throws SQLException {
        Integer startRow = (page_id - 1) * rownum;
        Integer endRow = page_id * rownum;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("page_id", page_id);
        map.put("keywords", keywords);
        return super.getSqlSession().selectList("Tab_ThesisNS.findSearch", map);

    }

    @Override
    public List<Tab_Thesis> findPage(Integer rownum, Integer page_id, String keywords) throws SQLException {
        Integer startRow = (page_id - 1) * rownum;
        Integer endRow = page_id * rownum ;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("page_id", page_id);
        map.put("keywords", keywords);
        return super.getSqlSession().selectList("Tab_ThesisNS.findPage", map);
    }

    @Override
    public Integer findCount(String keywords) throws SQLException {
        Map<String, String> map = new HashMap<>();
        map.put("keywords", keywords);
        return super.getSqlSession().selectOne("Tab_ThesisNS.findCount", map);
    }

    @Override
    public Integer searchCount(String keywords) throws SQLException {
        Map<String, String> map = new HashMap<>();
        map.put("keywords", keywords);
        return this.getSqlSession().selectOne("Tab_ThesisNS.searchCount", map);
    }

    @Override
    public Tab_Thesis list_reference(Integer i_id) throws SQLException {
        Map map = new HashMap<>();

        map.put("i_id", i_id);
        return super.getSqlSession().selectOne("Tab_ThesisNS.findReference", map);
    }

    @Override
    public List<Tab_Thesis> findNO_tj(Integer i_id) throws SQLException {
        Map map = new HashMap<>();
        map.put("i_id", i_id);
        return super.getSqlSession().selectList("Tab_ThesisNS.findNO_tj", map);
    }

    @Override
    public List<Tab_Thesis> findPage_tj(Integer rownum, Integer page_id) throws SQLException {
        Integer startRow = (page_id - 1) * rownum;
        Integer endRow = page_id * rownum ;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("page_id", page_id);

        return super.getSqlSession().selectList("Tab_ThesisNS.findPage_tj", map);
    }

    @Override
    public Integer findCount_tj() throws SQLException {
        return super.getSqlSession().selectOne("Tab_ThesisNS.findCount_tj");
    }

    @Override
    public List<Tab_Thesis> find_Bybooks(String id) throws SQLException {
        Map map = new HashMap<>();
        map.put("id", id);
        return super.getSqlSession().selectList("Tab_ThesisNS.find_Bybooks", map);
    }

    @Override
    public List<Tab_Thesis> findSearch_jl(Integer page_id, String keywords, Integer type, String mold) throws SQLException {
        Integer startRow = (page_id - 1) * 20;
        Integer endRow = (page_id - 1) * 20 + 20;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("page_id", page_id);
        map.put("keywords", keywords);
        map.put("type", type);
        map.put("mold", mold);
        return super.getSqlSession().selectList("Tab_ThesisNS.findPage_jl", map);
    }

    @Override
    public List<resultType_jl> searchCount_jl(String keywords, String mold) throws SQLException {
        Map map = new HashMap<>();
        map.put("keywords", keywords);
        map.put("mold", mold);
        return super.getSqlSession().selectList("Tab_ThesisNS.findCount_jl", map);
    }

    @Override
    public Integer CountPage_jl(String keywords, String value, Integer type) throws SQLException {
        Map map = new HashMap<>();
        map.put("keywords", keywords);
        map.put("value", value);
        map.put("type", type);
        return super.getSqlSession().selectOne("Tab_ThesisNS.CountPage_jl", map);
    }

    @Override
    public List<Tab_Thesis> findNO_kj(Integer i_id) throws SQLException {
        Map map = new HashMap<>();
        map.put("i_id", i_id);
        return super.getSqlSession().selectList("Tab_ThesisNS.findNO_kj", map);
    }

    @Override
    public List<Tab_Thesis> findPage_kj(Integer rownum, Integer page_id) throws SQLException {
        Integer startRow = (page_id - 1) * rownum;
        Integer endRow = page_id * rownum ;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("page_id", page_id);
        return super.getSqlSession().selectList("Tab_ThesisNS.findPage_kj", map);
    }

    @Override
    public Integer findCount_kj() throws SQLException {
        return super.getSqlSession().selectOne("Tab_ThesisNS.findCount_kj");
    }

    @Override
    public List finhome_kj() throws SQLException {
        return super.getSqlSession().selectList("Tab_ThesisNS.find_home_kj");
    }

    @Override
    public List<Tab_Thesis> search1(Integer page_id, String mold, Integer type) throws SQLException {
        Integer startRow = (page_id - 1) * 20;
        Integer endRow = (page_id - 1) * 20 + 20;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("mold", mold);
        map.put("type", type);
        return super.getSqlSession().selectList("Tab_ThesisNS.search1", map);
    }

    @Override
    public Integer count1() throws SQLException {
        Map map = new HashMap<>();
        Integer tmp = super.getSqlSession().selectOne("Tab_ThesisNS.count1", map);
        return tmp;
    }

    @Override
    public List<Tab_Thesis> search2(Integer page_id, String mold, Integer type) throws SQLException {
        Integer startRow = (page_id - 1) * 20;
        Integer endRow = (page_id - 1) * 20 + 20;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("mold", mold);
        map.put("type", type);
        return super.getSqlSession().selectList("Tab_ThesisNS.search2", map);
    }

    @Override
    public Integer count2() throws SQLException {
        Map map = new HashMap<>();
        Integer tmp = super.getSqlSession().selectOne("Tab_ThesisNS.count2", map);
        return tmp;
    }

    @Override
    public List<Tab_Thesis> search3(Integer page_id, String mold, Integer type) throws SQLException {
        Integer startRow = (page_id - 1) * 20;
        Integer endRow = (page_id - 1) * 20 + 20;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("mold", mold);
        map.put("type", type);
        return super.getSqlSession().selectList("Tab_ThesisNS.search3", map);
    }

    @Override
    public Integer count3() throws SQLException {
        Map map = new HashMap<>();
        Integer tmp = super.getSqlSession().selectOne("Tab_ThesisNS.count3", map);
        return tmp;
    }

    @Override
    public List<Tab_Thesis> search4(Integer page_id, String mold, Integer type) throws SQLException {
        Integer startRow = (page_id - 1) * 20;
        Integer endRow = (page_id - 1) * 20 + 20;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("mold", mold);
        map.put("type", type);
        return super.getSqlSession().selectList("Tab_ThesisNS.search4", map);
    }

    @Override
    public Integer count4() throws SQLException {
        Map map = new HashMap<>();
        Integer tmp = super.getSqlSession().selectOne("Tab_ThesisNS.count4", map);
        return tmp;
    }

    @Override
    public List<Tab_Thesis> search5(Integer page_id, String mold, Integer type) throws SQLException {
        Integer startRow = (page_id - 1) * 20;
        Integer endRow = (page_id - 1) * 20 + 20;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("mold", mold);
        map.put("type", type);
        return super.getSqlSession().selectList("Tab_ThesisNS.search5", map);
    }

    @Override
    public Integer count5() throws SQLException {
        Map map = new HashMap<>();
        Integer tmp = super.getSqlSession().selectOne("Tab_ThesisNS.count5", map);
        return tmp;
    }

    @Override
    public List<Tab_Thesis> combSearch(Integer page_id, String title, String author, String publisher, String metting, String op1, String op2, String op3) throws SQLException {
        Integer startRow = (page_id - 1) * 20;
        Integer endRow = (page_id - 1) * 20 + 20;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("title", title);
        map.put("author", author);
        map.put("publisher", publisher);
        map.put("metting", metting);
        map.put("op1", op1);
        map.put("op2", op2);
        map.put("op3", op3);
        return super.getSqlSession().selectList("Tab_ThesisNS.combSearch", map);
    }

    @Override
    public Integer combSearchCount(Integer page_id, String title, String author, String publisher, String metting, String op1, String op2, String op3) throws SQLException {
        Integer startRow = (page_id - 1) * 20;
        Integer endRow = (page_id - 1) * 20 + 20;
        Map map = new HashMap<>();
        map.put("startRow", startRow);
        map.put("endRow", endRow);
        map.put("title", title);
        map.put("author", author);
        map.put("publisher", publisher);
        map.put("metting", metting);
        map.put("op1", op1);
        map.put("op2", op2);
        map.put("op3", op3);
        Integer tmp = super.getSqlSession().selectOne("Tab_ThesisNS.combSearchCount", map);
        return tmp;
    }

    @Override
    public List<resultType_jl> combSearchStat(String title, String author, String publisher, String metting, String op1, String op2, String op3, String mold) throws SQLException {
        Map map = new HashMap<>();
        map.put("title", title);
        map.put("author", author);
        map.put("publisher", publisher);
        map.put("metting", metting);
        map.put("op1", op1);
        map.put("op2", op2);
        map.put("op3", op3);
        map.put("mold", mold);
        return super.getSqlSession().selectList("Tab_ThesisNS.combSearchStat", map);
    }

    @Override
    public List<resultType_jl> stat1(String mold) throws SQLException {
        Map map = new HashMap<>();
        map.put("mold", mold);
        return super.getSqlSession().selectList("Tab_ThesisNS.stat1", map);
    }

    @Override
    public List<resultType_jl> stat2(String mold) throws SQLException {
        Map map = new HashMap<>();
        map.put("mold", mold);
        return super.getSqlSession().selectList("Tab_ThesisNS.stat2", map);
    }

    @Override
    public List<resultType_jl> stat3(String mold) throws SQLException {
        Map map = new HashMap<>();
        map.put("mold", mold);
        return super.getSqlSession().selectList("Tab_ThesisNS.stat3", map);
    }

    @Override
    public List<resultType_jl> stat4(String mold) throws SQLException {
        Map map = new HashMap<>();
        map.put("mold", mold);
        return super.getSqlSession().selectList("Tab_ThesisNS.stat4", map);
    }

    @Override
    public List<resultType_jl> stat5(String mold) throws SQLException {
        Map map = new HashMap<>();
        map.put("mold", mold);
        return super.getSqlSession().selectList("Tab_ThesisNS.stat5", map);
    }

    @Override
    public List<Tab_Thesis> selectWordCount() throws SQLException {
        Map map = new HashMap<>();
        return super.getSqlSession().selectList("Tab_ThesisNS.selectWordCount", map);
    }
}
